package com.zznj.xzjc.activity.diaochaquzheng;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.amap.api.location.AMapLocation;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.style.PictureWindowAnimationStyle;
import com.luck.picture.lib.tools.ScreenUtils;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.view.RxToast;
import com.vondear.rxui.view.dialog.RxDialogCaiLiaoYaoQiu;
import com.vondear.rxui.view.dialog.RxDialogChooseCaiLiaoUpload;
import com.vondear.rxui.view.dialog.RxDialogDownload;
import com.vondear.rxui.view.dialog.RxDialogSelectZhengJuType;
import com.vondear.rxui.view.dialog.RxDialogSureCancel;
import com.zznj.xzjc.R;
import com.zznj.xzjc.activity.ActivityFile;
import com.zznj.xzjc.activity.FileDisplayActivity;
import com.zznj.xzjc.activity.NetPicShowActivity;
import com.zznj.xzjc.adapter.QzdsrAdapter;
import com.zznj.xzjc.adapter.QzjddwAdapter;
import com.zznj.xzjc.adapter.TypeCaiLiaoAdapter;
import com.zznj.xzjc.adapter.ZhengJuListAdapter;
import com.zznj.xzjc.application.APP;
import com.zznj.xzjc.base.BaseActivity;
import com.zznj.xzjc.bean.JddwBean;
import com.zznj.xzjc.bean.index.DsrBean;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.BaseBean;
import com.zznj.xzjc.net.entity.DiaoChaQuZhengBean;
import com.zznj.xzjc.net.entity.DictionaryBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.net.entity.ZhengJuBean;
import com.zznj.xzjc.net.rxjava.HttpMethods;
import com.zznj.xzjc.net.subscribers.ProgressSubscriber;
import com.zznj.xzjc.net.subscribers.SubscriberOnNextListener;
import com.zznj.xzjc.utils.FileUtils;
import com.zznj.xzjc.utils.GlideEngine;
import com.zznj.xzjc.utils.LocationUtil;
import com.zznj.xzjc.utils.StringUtils;
import com.zznj.xzjc.utils.TimeUtils;
import com.zznj.xzjc.utils.fileutils.OkManager;
import com.zznj.xzjc.widget.TabScrollView;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


/**
 * Created by JY on 2017/11/15.
 */

public class DaoChaQuZhengDetailActivity extends BaseActivity {

    @BindView(R.id.tv_ajmc)
    TextView tv_ajmc;
    @BindView(R.id.tv_cbbm)
    TextView tv_cbbm;
    @BindView(R.id.tv_cbsj)
    TextView tv_cbsj;

    @BindView(R.id.tv_cbjcg)
    TextView tv_cbjcg;
    @BindView(R.id.tv_slsj)
    TextView tv_slsj;
    @BindView(R.id.tv_xslx)
    TextView tv_xslx;
    @BindView(R.id.tv_wflx)
    TextView tv_wflx;
    @BindView(R.id.tv_xzxw)
    TextView tv_xzxw;
    @BindView(R.id.tv_xsxz)
    TextView tv_xsxz;

    @BindView(R.id.baseInfoScroll)
    View baseInfoScroll;


    @BindView(R.id.tv_wfxw)
    TextView tv_wfxw;
    @BindView(R.id.btn_zjclsc)
    TextView btn_zjclsc;
    @BindView(R.id.btn_jsdc)
    TextView btn_jsdc;

    @BindView(R.id.zjcl_linear)
    View zjcl_linear;
    @BindView(R.id.type_tab)
    TabScrollView tabScroll;
    @BindView(R.id.rec_main)
    RecyclerView recMain;

    @BindView(R.id.jddwRec)
    RecyclerView jddwRec;



    @BindView(R.id.zjsjyqLinear)
    View zjsjyqLinear;

    @BindView(R.id.tv_jbxx)
    TextView tv_jbxx;
    @BindView(R.id.jbxx_line)
    View jbxx_line;
    @BindView(R.id.tv_zjcl)
    TextView tv_zjcl;
    @BindView(R.id.zjcl_line)
    View zjcl_line;

    @BindView(R.id.line)
    View line;

    @BindView(R.id.tishiImg)
    View tishiImg;

    @BindView(R.id.msgyssxxLinear)
    View msgyssxxLinear;





    private int selectTab = 0;

    private List<String> titleList = new ArrayList<>();
    private String clueId;
    private String clueName;
    private void initTab() {
        tabScroll.setTitles(titleList)
                .setTabScrollHeight(ScreenUtils.dip2px(mContext, 45))
                .setSelectTextColor(R.color.color_333333)
                .setUnSelectTextColor(R.color.color_333333)
                .setTitleTextSize(14)
                .setSelectBgIcon(R.color.white)
                .setUnSelectBgIcon(R.color.transparent)
                .createTab();
        tabScroll.setTypeClickListener(new TabScrollView.TypeClickListener() {
            @Override
            public void typeClick(TabScrollView.MyRelativeLayout myTextView, int position) {
                selectTitle = myTextView.getTextView().getText().toString();
                clList = fileMap.get(selectTitle);
                if (clList == null) {
                    clList = new ArrayList<>();
                    tishiImg.setVisibility(View.VISIBLE);
                }else{
                    tishiImg.setVisibility(View.GONE);
                }
                zjListAdapter.setNewData(clList);
            }
        });
    }

    private void delFile(String evidenceMaterialId) {
        SubscriberOnNextListener<BaseBean> onNextListener = baseBean -> {
            if(baseBean.isSuccess()){
                getDetail();
                RxToast.normal("删除成功！");
            }
        };
        FormBody requestBody = new FormBody.Builder()
                .add("evidenceMaterialId", evidenceMaterialId)
                .build();
        HttpMethods.getInstance().delEvidenceMaterial(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }

    private void initDialog(String content,String evidenceMaterialId) {
        RxDialogSureCancel rxDialogEditSureCancel = new RxDialogSureCancel(mContext);
        rxDialogEditSureCancel.getLogoView().setVisibility(View.GONE);
        rxDialogEditSureCancel.getTitleView().setTextSize(18);
        rxDialogEditSureCancel.getTitleView().setTextColor(Color.BLACK);
        rxDialogEditSureCancel.setTitle("提示");
        rxDialogEditSureCancel.setContent(content);
        rxDialogEditSureCancel.setCancelListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rxDialogEditSureCancel.dismiss();
            }
        });
        rxDialogEditSureCancel.setSureListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rxDialogEditSureCancel.dismiss();
                delFile(evidenceMaterialId);
            }
        });
        rxDialogEditSureCancel.show();
    }

    private List<ZhengJuBean> clList;
    private ZhengJuListAdapter zjListAdapter;

    private void init() {
        clList = new ArrayList<>();
        ((SimpleItemAnimator) recMain.getItemAnimator()).setSupportsChangeAnimations(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        recMain.setLayoutManager(linearLayoutManager);
        zjListAdapter = new ZhengJuListAdapter(R.layout.gyss_item_cailiao, clList);
        recMain.setAdapter(zjListAdapter);

        zjListAdapter.setOnItemLongClickListener(new BaseQuickAdapter.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(BaseQuickAdapter adapter, View view, int position) {
                //删除数据
                ZhengJuBean zjObj = clList.get(position);
                initDialog("确定删除该文件？",zjObj.getEvidenceMaterialId());
                return false;
            }
        });

        zjListAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                ZhengJuBean obj = clList.get(position);
                if (FileUtils.getIcon(obj.getName()) == R.mipmap.icon_file_pic) {
                    //打开图片
//                    getHttpUrlById(obj.getId());
                    List<String> pList = new ArrayList<>();
                    pList.add(HttpMethods.BASE_File_URL+obj.getId());
                    Bundle bundle = new Bundle();
                    bundle.putInt("item", 0);
                    bundle.putSerializable("listPath", (Serializable) pList);
                    RxActivityTool.skipActivity(mContext, NetPicShowActivity.class, bundle);
//                }else if(FileUtils.getIcon(obj.getName()) == R.mipmap.icon_file_video){
                    //视频
//                    Bundle bundle = new Bundle();
//                    bundle.putString("videoPath",HttpMethods.BASE_File_URL+obj.getId()); //
//                    RxActivityTool.skipActivity(mContext, VedioMsgActivity.class,bundle);
                }else{
                    //下载文件
                    String downPath  = HttpMethods.BASE_File_URL+obj.getId();
                    downFile(downPath,obj.getName());
                }
            }
        });
    }

    private void downFile(String downUrl,String fileName){
        File pFile = new File(FileUtils.getRootFile(),fileName);
        if (!pFile.exists()) {
            initSexDialog();
            OkManager.getInstance().downLoadFile(downUrl, fileName, new Handler(){
                @Override
                public void handleMessage(@NonNull Message msg) {
                    downDialog.dismiss();
                    if(msg.what == 100){
                        RxToast.normal("下载成功！");
                        Bundle bundle = new Bundle();
                        bundle.putString("fileName",fileName);
                        RxActivityTool.skipActivity(activity, FileDisplayActivity.class,bundle);
                    }else if(msg.what == -1){
                        RxToast.normal("下载失败！");
                        pFile.delete();
                    }
                    super.handleMessage(msg);
                }
            });
        }else{
//            CallOtherOpeanFile.openFile(mContext,pFile);
            Bundle bundle = new Bundle();
            bundle.putString("fileName",fileName);
            RxActivityTool.skipActivity(activity, FileDisplayActivity.class,bundle);
        }
    }
    private RxDialogDownload downDialog;
    private void initSexDialog() {
        downDialog = new RxDialogDownload(this);
        downDialog.setCanceledOnTouchOutside(false);
        downDialog.getTextView().setText("下载中...");
        downDialog.show();
    }



//    private Handler handler = new Handler(){
//        @Override
//        public void handleMessage(@NonNull Message msg) {
//            if(msg.what == 100){
//                downDialog.dismiss();
//            }
//            RxToast.normal(msg.what+"");
//            super.handleMessage(msg);
//        }
//    };



    /**
     * 监督单位
     * @param jddwList
     */
    private void initJddw(List<JddwBean> jddwList) {
        ((SimpleItemAnimator) jddwRec.getItemAnimator()).setSupportsChangeAnimations(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        jddwRec.setLayoutManager(linearLayoutManager);
        QzjddwAdapter adapter = new QzjddwAdapter(R.layout.gyss_item_qz_jddw, jddwList);
        jddwRec.setAdapter(adapter);
    }

    private void initDsr(List<DsrBean> dsrList) {
        ((SimpleItemAnimator) jddwRec.getItemAnimator()).setSupportsChangeAnimations(false);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        jddwRec.setLayoutManager(linearLayoutManager);
        QzdsrAdapter adapter = new QzdsrAdapter(R.layout.gyss_item_qz_jddw, dsrList);
        jddwRec.setAdapter(adapter);

    }

    @Override
    protected int getLayoutId() {
        return R.layout.gyss_activity_diaochaquzheng_layout;
    }

    @Override
    public void initView() {
        setTitle("调查取证详情");
        btnRight.setVisibility(View.GONE);
        zjsjyqLinear.setVisibility(View.VISIBLE);
        clueId = getIntent().getExtras().getString("clueId");
        clueName = getIntent().getExtras().getString("clueName");
        init();
        zjsjyqLinear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getYaoQiu();
            }
        });

        tv_jbxx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectTab = 0;
                tv_jbxx.setTypeface(Typeface.DEFAULT_BOLD);
                jbxx_line.setVisibility(View.VISIBLE);
                tv_zjcl.setTypeface(Typeface.DEFAULT);
                zjcl_line.setVisibility(View.INVISIBLE);
                baseInfoScroll.setVisibility(View.VISIBLE);
                zjcl_linear.setVisibility(View.GONE);
                line.setVisibility(View.INVISIBLE);

            }
        });
        tv_zjcl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                selectTab = 1;
                tv_zjcl.setTypeface(Typeface.DEFAULT_BOLD);
                zjcl_line.setVisibility(View.VISIBLE);
                tv_jbxx.setTypeface(Typeface.DEFAULT);
                jbxx_line.setVisibility(View.INVISIBLE);
                zjcl_linear.setVisibility(View.VISIBLE);
                baseInfoScroll.setVisibility(View.GONE);
                zjListAdapter.setNewData(clList);
                if(clList != null && clList.size()>0){
                    tishiImg.setVisibility(View.GONE);
                }else{
                    tishiImg.setVisibility(View.VISIBLE);
                }
                line.setVisibility(View.VISIBLE);
            }
        });

        btn_zjclsc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showRxDialogSelectZhengJuType();
            }
        });
        btn_jsdc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //结束调查
                close();
            }
        });
    }

    //结束调查
    private void close(){
        SubscriberOnNextListener<BaseBean<DiaoChaQuZhengBean>> onNextListener = baseBean -> {
            if(baseBean.isSuccess()){
                RxToast.normal("操作成功！");
                finish();
            }
        };
        FormBody requestBody = new FormBody.Builder()
                .add("clueId", clueId)
                .build();
        HttpMethods.getInstance().finishSurvey(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }


    private RxDialogCaiLiaoYaoQiu rxYaoQiuDialog;

    private void showRxDialogCaiLiaoYaoQiu() {
        if (rxYaoQiuDialog == null) {
            rxYaoQiuDialog = new RxDialogCaiLiaoYaoQiu(mContext, R.style.dialogStyle);
            rxYaoQiuDialog.setCloseLinstener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    rxYaoQiuDialog.dismiss();
                }
            });
        }
        rxYaoQiuDialog.getTvContent().setMovementMethod(ScrollingMovementMethod.getInstance());
        rxYaoQiuDialog.getTitleTv().setText(resData.getClueTypeName());
        rxYaoQiuDialog.getTvContent().setText(Html.fromHtml(clyqArgs));
        rxYaoQiuDialog.show();
    }

    private RxDialogSelectZhengJuType rxZhengJuTypeDialog;
    private RecyclerView typeSrc;
    private TypeCaiLiaoAdapter tcAdapter;
    private DictionaryBean zjlxSelect;

    private void showRxDialogSelectZhengJuType() {
        if (rxZhengJuTypeDialog == null) {
            rxZhengJuTypeDialog = new RxDialogSelectZhengJuType(mContext, R.style.dialogStyle);
            rxZhengJuTypeDialog.setCloseLinstener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    rxZhengJuTypeDialog.dismiss();
                }
            });
        }

        if (tcAdapter == null) {
            typeSrc = rxZhengJuTypeDialog.getTypeRec();
            GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, 2);
            typeSrc.setLayoutManager(gridLayoutManager);


            tcAdapter = new TypeCaiLiaoAdapter(R.layout.gyss_item_cailiaotype, tabList);
            tcAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    rxZhengJuTypeDialog.dismiss();
                    zjlxSelect = tabList.get(position);
                    showRxDialogChooseCaiLiaoUpload();
                }
            });
            typeSrc.setAdapter(tcAdapter);
        }
        tcAdapter.notifyDataSetChanged();
        rxZhengJuTypeDialog.show();
    }

    private RxDialogChooseCaiLiaoUpload rxDialogChooseCaiLiaoUpload;

    private void showRxDialogChooseCaiLiaoUpload() {
        if (rxDialogChooseCaiLiaoUpload == null) {
            rxDialogChooseCaiLiaoUpload = new RxDialogChooseCaiLiaoUpload(mContext);

            rxDialogChooseCaiLiaoUpload.setFileClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    RxActivityTool.skipActivityForResult(activity, ActivityFile.class, 3);
                    rxDialogChooseCaiLiaoUpload.dismiss();
                }
            });
            rxDialogChooseCaiLiaoUpload.setPicClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    checkImage();
                    rxDialogChooseCaiLiaoUpload.dismiss();
                }
            });
            rxDialogChooseCaiLiaoUpload.setVedioClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    checkVedio();
                    rxDialogChooseCaiLiaoUpload.dismiss();
                }
            });
        }
        rxDialogChooseCaiLiaoUpload.show();
    }

    private List<LocalMedia> localMediaList = new ArrayList<>();

    private void checkImage() {
        PictureSelector.create(DaoChaQuZhengDetailActivity.this)
                .openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                .setPictureWindowAnimationStyle(new PictureWindowAnimationStyle())// 自定义相册启动退出动画
                .loadImageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项   参考Demo MainActivity中代码
                .isWeChatStyle(true)// 是否开启微信图片选择风格，此开关开启了才可使用微信主题！！！
                .isAndroidQTransform(true)// 是否需要处理Android Q 拷贝至应用沙盒的操作，只针对compress(false); && enableCrop(false);有效
                .maxSelectNum(9)// 最大图片选择数量 int
                .minSelectNum(1)// 最小选择数量 int
                .imageSpanCount(4)// 每行显示个数 int
                .isNotPreviewDownload(true)// 预览图片长按是否可以下载
                .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                .queryMaxFileSize(50)// 只查多少M以内的图片、视频、音频  单位M
                .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
                .previewImage(true)// 是否可预览图片 true or false
                .isCamera(true)// 是否显示拍照按钮 true or false
//                .imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
//                .setOutputCameraPath("/CustomPath")// 自定义拍照保存路径,可不填
                .enableCrop(false)// 是否裁剪 true or false
                .compress(true)// 是否压缩 true or false
                .isGif(true)// 是否显示gif图片 true or false
                //   .compressSavePath(getPath())//压缩图片保存地址
                .openClickSound(false)// 是否开启点击声音 true or false
                .cutOutQuality(90)// 裁剪输出质量 默认100
                .minimumCompressSize(100)// 小于100kb的图片不压缩
                .forResult(1);//结果回调onActivityResult code
    }

    private void checkVedio() {
        PictureSelector.create(activity)
                .openGallery(PictureMimeType.ofVideo())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                .setPictureWindowAnimationStyle(new PictureWindowAnimationStyle())// 自定义相册启动退出动画
                .loadImageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项   参考Demo MainActivity中代码
                .videoQuality(1)
                .isWeChatStyle(true)// 是否开启微信图片选择风格，此开关开启了才可使用微信主题！！！
                .isAndroidQTransform(true)// 是否需要处理Android Q 拷贝至应用沙盒的操作，只针对compress(false); && enableCrop(false);有效
                .maxSelectNum(1)// 最大图片选择数量 int
                .minSelectNum(1)// 最小选择数量 int
                .imageSpanCount(3)// 每行显示个数 int
                .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                .isNotPreviewDownload(true)// 预览图片长按是否可以下载
                .queryMaxFileSize(100)// 只查多少M以内的图片、视频、音频  单位M
                .isSingleDirectReturn(false)// 单选模式下是否直接返回，PictureConfig.SINGLE模式下有效
                .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
                .previewImage(true)// 是否可预览图片 true or false
                .isCamera(true)// 是否显示拍照按钮 true or false
                .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
                .sizeMultiplier(0.5f)// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
//                .setOutputCameraPath("/CustomPath")// 自定义拍照保存路径,可不填
                .enableCrop(false)// 是否裁剪 true or false
                .compress(true)// 是否压缩 true or false
                .isGif(true)// 是否显示gif图片 true or false
                //   .compressSavePath(getPath())//压缩图片保存地址
                .openClickSound(false)// 是否开启点击声音 true or false
                .cutOutQuality(90)// 裁剪输出质量 默认100
                .minimumCompressSize(100)// 小于100kb的图片不压缩
//                .videoMaxSecond(300)
//                .videoMinSecond(5)
//                .recordVideoSecond(20)
                .forResult(2);//结果回调onActivityResult code
    }


    @Override
    public void initData() {
        getDictionaryTab();
        getDetail();
    }

    private Map<String, List<ZhengJuBean>> fileMap;
    private DiaoChaQuZhengBean resData;
    private void getDetail() {
        SubscriberOnNextListener<BaseBean<DiaoChaQuZhengBean>> onNextListener = baseBean -> {

            resData = baseBean.getResult();

            tv_ajmc.setText(StringUtils.toStringForWu(resData.getClueName()));
            tv_cbbm.setText(StringUtils.toStringForWu(resData.getUnderDepartment()));
            tv_cbsj.setText(TimeUtils.getTime(resData.getUnderTime(),"yyyy-MM-dd"));
            tv_cbjcg.setText(StringUtils.toStringForWu(resData.getUndertaker()));
            tv_slsj.setText(TimeUtils.getTime(resData.getAcceptTime(),"yyyy-MM-dd"));
            tv_xslx.setText(StringUtils.toStringForWu(resData.getClueDomainName()));
            tv_wflx.setText(StringUtils.toStringForWu(resData.getClueDomainChildName()));
            tv_xzxw.setText(StringUtils.toStringForWu(resData.getAdministrativeBehavior()));
            tv_xsxz.setText(StringUtils.toStringForWu(resData.getCaseNatureName()));

            tv_wfxw.setText(StringUtils.toStringForWu(resData.getRuleName()));

            if("msgyssxs".equals(resData.getClueType())){
                msgyssxxLinear.setVisibility(View.GONE);
            }

            if (!StringUtils.isEmpty(resData.getGroupFileJsons())) {
                fileMap = new Gson().fromJson(resData.getGroupFileJsons(), new TypeToken<Map<String, List<ZhengJuBean>>>() {
                }.getType());
                clList = fileMap.get(selectTitle);
                zjListAdapter.setNewData(clList);
                if(clList != null && clList.size() > 0){
                    tishiImg.setVisibility(View.GONE);
                }else{
                    tishiImg.setVisibility(View.VISIBLE);
                }
            }

            //处理当事人，监督单位
            if(StringUtils.isEmptyForContent(resData.getSuperviseOrgListStr())){
                jddwRec.setVisibility(View.GONE);
            }else{
                if("行政公益诉讼线索".equals(resData.getClueTypeName())){
                    initJddw(new Gson().fromJson(resData.getSuperviseOrgListStr(),new TypeToken<List<JddwBean>>(){}.getType()));
                }else{
                    initDsr(new Gson().fromJson(resData.getSuperviseOrgListStr(),new TypeToken<List<DsrBean>>(){}.getType()));
                }
                jddwRec.setVisibility(View.VISIBLE);
            }
        };
        FormBody requestBody = new FormBody.Builder()
                .add("clueId", clueId)
                .build();
        HttpMethods.getInstance().ourClueGet(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }

    private List<DictionaryBean> tabList;
    private String selectTitle;

    private void getDictionaryTab() {
        SubscriberOnNextListener<BaseBean<List<DictionaryBean>>> onNextListener = baseBean -> {
//            tabList = baseBean.getResult();
//            selectTitle = tabList.get(0).getItemName();
//            titleList.clear();
//            for (int i = 0; i < tabList.size(); i++) {
//                titleList.add(tabList.get(i).getItemName());
//            }
//            initTab();
//            getDetail();
        };
        LoginBean user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        FormBody requestBody = new FormBody.Builder()
                .add("nodeKey", "zjfl")
                .build();
        HttpMethods.getInstance().getFindXianSuoDictionary(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }

    private String clyqArgs;

    private void getYaoQiu() {
        SubscriberOnNextListener<BaseBean<String>> onNextListener = baseBean -> {
            clyqArgs = baseBean.getResult();
            showRxDialogCaiLiaoYaoQiu();
        };
        FormBody requestBody = new FormBody.Builder()
                .add("ruleId", resData.getRuleId())
                .build();
        HttpMethods.getInstance().getEvidenceDemand(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        if (resultCode == RESULT_OK) {
            if (requestCode == 1) {
                List<LocalMedia> list = PictureSelector.obtainMultipleResult(data);
//                String path;
//                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
//                    path = PictureSelector.obtainMultipleResult(data).get(0).getAndroidQToPath();
//                }else{
//                    path = PictureSelector.obtainMultipleResult(data).get(0).getPath();
//                }
                //上传文件
                for(int i=0;i<list.size();i++){
                    uploadFile(list.get(i).getCompressPath());
                }
            } else if (requestCode == 2) {
                if (!PictureSelector.obtainMultipleResult(data).isEmpty()) {
                    String path;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                        path = PictureSelector.obtainMultipleResult(data).get(0).getAndroidQToPath();
                    }else{
                        path = PictureSelector.obtainMultipleResult(data).get(0).getPath();
                    }
                    //上传文件
                    uploadFile(path);
//                    aaa(path);
                }
            } else if (requestCode == 3) {
                String path = data.getStringExtra("filePath");
                //上传文件
                uploadFile(path);
            }
        }
    }

    private double lng, lat;
    private String address;
    private LocationUtil locationUtil;

    private void initLoc() {
        locationUtil = new LocationUtil(this);
        locationUtil.dingwei();
        locationUtil.setOnLocChangedListener(new LocationUtil.OnLocChangedListener() {
            @Override
            public void onLocationChanged(AMapLocation loc) {
                lng = loc.getLongitude();
                lat = loc.getLatitude();
                locationUtil.stopLocation();
                locationUtil.destroyLocation();
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        initLoc();
    }

    private void uploadFile(String path) {
        File file = new File(path);
        RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"), file);
        SubscriberOnNextListener<BaseBean<ZhengJuBean>> onNextListener = baseBean -> {
            ZhengJuBean zj = new Gson().fromJson(baseBean.getMessage(), ZhengJuBean.class);
//            zj.setGroupName(zjlxSelect.getItemName());
            zj.setUploadAddress(address);
            zj.setLat(lat + "");
            zj.setLng(lng + "");
            zj.setName(new File(path).getName());
            zj.setFileSize(StringUtils.getPrintSize(file.length()));
            zj.setId(zj.getFileId());
            //保存上传信息
            saveUploadFile(zj);
        };
        LoginBean user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        Map<String, Object> fileMap = new HashMap<>();
        fileMap.put("uploadAddress", address);
        fileMap.put("lng", lng + "");
        fileMap.put("lat", lat + "");
        MultipartBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getName(), fileBody)
                .addFormDataPart("extendJson", new Gson().toJson(fileMap))
                .build();
        HttpMethods.getInstance().uploadFile(new ProgressSubscriber<>(onNextListener, mContext, true), body);
    }


    private void aaa(String path) {
        showProgressDialog();
        Map<String, Object> fileMap = new HashMap<>();
        fileMap.put("uploadAddress", address);
        fileMap.put("lng", lng + "");
        fileMap.put("lat", lat + "");
        Log.d("zhangshuai", "onFailure: 11111111111111" );
        //构建指定文件实例
        File file = new File(path);
        RequestBody requestBody = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("application/octet-stream"), file))
                .addFormDataPart("extendJson", new Gson().toJson(fileMap))
                .build();
        ProgressRequestBody pr = new ProgressRequestBody(requestBody, new ProgressResponseListener() {
            @Override
            public void onResponseProgress(long bytesRead, long contentLength, boolean done) {
                Log.d("zhangshuai",bytesRead+"");
            }
        });

        OkHttpClient okHttpClient = new OkHttpClient();
        String cookie = SharedHelper.readValueByKeyForString(APP.getInstance().getApplicationContext(),"cookie");

        Request request = new Request.Builder()
                .addHeader("cookie",cookie)
                .url(HttpMethods.BASE_URL+"sysFile/uploadFile.ht")
                //传入文件实例
                .post(requestBody)
                .build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d("zhangshuai", "onFailure: " + e.getMessage());
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("zhangshuai", " response.body() = " + response.body().string());
                Log.d("zhangshuai", " response.code() = " + response.code());
                Log.d("zhangshuai", " response.message() = " + response.message());
            }
        });
    }


    private void saveUploadFile(ZhengJuBean zj) {
        List<ZhengJuBean> zjList = new ArrayList<>();
        zjList.add(zj);
        SubscriberOnNextListener<BaseBean> onNextListener = baseBean -> {
            //保存上传信息
            RxToast.normal("上传成功！");
            getDetail();
        };
        LoginBean user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        FormBody requestBody = new FormBody.Builder()
                .add("fileJsons", new Gson().toJson(zjList))
                .add("clueId", clueId + "")
                .add("clueName", clueName)
                .build();
        HttpMethods.getInstance().evidenceMaterialSave(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }

    private void getHttpUrlById(String id) {
        SubscriberOnNextListener<BaseBean<String>> onNextListener = baseBean -> {
            List<String> pList = new ArrayList<>();
            pList.add(baseBean.getResult());
            Bundle bundle = new Bundle();
            bundle.putInt("item", 0);
            bundle.putSerializable("listPath", (Serializable) pList);
            RxActivityTool.skipActivity(this, NetPicShowActivity.class, bundle);

        };
        LoginBean user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        FormBody requestBody = new FormBody.Builder()
                .add("fileId", id)
                .build();
        HttpMethods.getInstance().getHttpUrlById(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }
}
